package march.view
{
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import utils.T;
	import vo.GeneralVO;
	
	/**
	 * ...
	 * @author WLDragon 2014-04-16
	 */
	public class Army extends Sprite
	{
		
		public function Army()
		{
			soldiersBmp = new Bitmap();
			soldiersBmp.y = 2;
			addChild(soldiersBmp);
			
			typeBmp = new Bitmap();
			typeBmp.x = 2;
			typeBmp.y = 18;
			addChild(typeBmp);
		
		}
		
		public function update(general:GeneralVO, isAttack:Boolean, isCaptain:Boolean = false):void
		{
			this.general = general;
			this.isAttack = isAttack;
			this.isCaptain = isCaptain;
			var n:String = String((general.soliders * 0.01) >> 0);
			soldiersBmp.x = n.length == 1?18:6;
			foreColor = isAttack == true ? 0x000000 : 0xFFC8B8;
			var bgColor:uint = isAttack == true ? 0xffffff : 0xE15000;
			soldiersBmp.bitmapData = T.font.getNumberBitmapData(n, "png.march.num", foreColor);
			typeBmp.bitmapData = T.font.getNumberBitmapData(String(general.armyType), "png.march.army", foreColor, 3);
			if (isCaptain)
			{
				var h:Bitmap = new Bitmap(T.font.getNumberBitmapData("0", "png.march.head", foreColor, 1));
				h.x = 2;
				h.y = 4;
				addChild(h);
			}
			with (graphics)
			{
				beginFill(bgColor);
				lineStyle(2);
				moveTo(1, 1);
				lineTo(31, 1);
				lineTo(31, 31);
				lineTo(1, 31);
				lineTo(1, 1);
				endFill();
			}
		}
		
		public function updateSoliders():void
		{
			var n:String = String((general.soliders * 0.01) >> 0);
			soldiersBmp.x = n.length == 1?18:6;
			soldiersBmp.bitmapData = T.font.getNumberBitmapData(n, "png.march.num", foreColor);
		}
		
		public function unActive():void
		{
			App.timer.clearTimer(loop);
			this.visible = true;
		}
		
		public function active():void
		{
			App.timer.doLoop(400, loop);
		}
		
		private function loop():void 
		{
			this.visible = !this.visible;
		}
		
		/**军种类型*/
		private var typeBmp:Bitmap;
		/**士兵数量位图显示*/
		private var soldiersBmp:Bitmap;
		/**士兵数量*/
		private var soldiers:int;
		/**前景色*/
		private var foreColor:uint;
		/**阵营，是否为攻方*/
		public var isAttack:Boolean;
		/**是否为主将*/
		public var isCaptain:Boolean;
		/***/
		public var general:GeneralVO;
	}

}